package cn.lumora.factory;

import cn.lumora.enums.LoginTypeEnum;
import cn.lumora.enums.RegisterTypeEnum;
import cn.lumora.strategy.LoginStrategy;
import cn.lumora.strategy.RegisterStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RegisterStrategyFactory {

    private final Map<String, RegisterStrategy> strategies;

    @Autowired
    public RegisterStrategyFactory(Map<String, RegisterStrategy> strategies) {
        this.strategies = strategies;
    }

    public RegisterStrategy getStrategy(String loginType) {
        return strategies.get(loginType + "LoginStrategy");
    }

    // 新增：根据数字编号获取
    public RegisterStrategy getStrategy(int loginTypeCode) {
        String beanName = RegisterTypeEnum.getBeanNameByCode(loginTypeCode);
        return strategies.get(beanName);
    }
}
